package com.ztman.router.common.core.prefer;

import android.content.Context;
import android.content.SharedPreferences;

import com.ztman.router.common.base.MyApplication;
import com.ztman.router.common.utils.Constants;

import javax.inject.Inject;

/**
 * @Title:PreferenceHelperImpl
 * @Package:com.ztman.router.common.core
 * @Description:对登陆用户的登陆状态、账户、密码 进行存储的具体实现类
 * @Auther:YJH
 * @Email:yuannunhua@gmail.com
 * @Date:2018/5/1611:45
 */
public class PreferenceHelperImpl implements PreferenceHelper {

    private static final String MY_SHARED_PREFERENCE = "my_shared_preference";
    private SharedPreferences mPreferences;

    @Inject
    PreferenceHelperImpl(){
        mPreferences = MyApplication.getInstance().getSharedPreferences(MY_SHARED_PREFERENCE, Context.MODE_PRIVATE);
    }

    @Override
    public void setLoginAccount(String account) {
        mPreferences.edit().putString(Constants.ACCOUNT, account).apply();
    }

    @Override
    public void setLoginPassword(String password) {
        mPreferences.edit().putString(Constants.PASSWORD, password).apply();
    }

    @Override
    public String getLoginAccount() {
        return mPreferences.getString(Constants.ACCOUNT, "");
    }

    @Override
    public String getLoginPassword() {
        return mPreferences.getString(Constants.PASSWORD, "");
    }

    @Override
    public void setLoginStatus(boolean isLogin) {
        mPreferences.edit().putBoolean(Constants.LOGIN_STATUS, isLogin).apply();
    }

    @Override
    public boolean getLoginStatus() {
        return mPreferences.getBoolean(Constants.LOGIN_STATUS, false);
    }
}
